function getSharePic(obj) {

	return new Promise(function (resolve, reject) {
		var canvasData = obj;
		//获取窗口信息
		console.log('getSharePic------------------------------------');
		console.log(canvasData);
		//canvasData.pixelRatio = canvasData.pixelRatio.toFixed(1);
		var demandInfo = obj.demandInfo;
		var that = this;
		const ctx = uni.createCanvasContext('myCanvas');
		ctx.beginPath();
		ctx.setFillStyle('#FFFFFF');
		ctx.width = canvasData.windowWidth;
		ctx.height = canvasData.windowHeight;
		ctx.fillRect(0, 0, canvasData.windowWidth, canvasData.windowHeight);
		ctx.fill();
		ctx.closePath();
		//ctx.save();
		// 外面方框
		ctx.beginPath();
		ctx.setStrokeStyle('#e5e5e5');
		ctx.setLineWidth(1);
		roundRect(ctx, 29 / canvasData.pixelRatio, 29 / canvasData.pixelRatio, 711 / canvasData.pixelRatio, 414 / canvasData.pixelRatio, 8);
		ctx.stroke();
		ctx.closePath();

		ctx.beginPath();
		ctx.setFontSize(28 / canvasData.pixelRatio);
		ctx.setFillStyle('#1a1a1a');
		ctx.setTextAlign('left');
		ctx.fillText(demandInfo.goodsName, 49 / canvasData.pixelRatio, 89 / canvasData.pixelRatio);
		ctx.closePath();
		// 发布时间
		let startx = 691 - (demandInfo.publishTime.length + 1) * 20 / canvasData.pixelRatio;
		ctx.beginPath();
		ctx.setFontSize(20 / canvasData.pixelRatio);
		ctx.setFillStyle('#737880');
		ctx.setTextAlign('left');
		ctx.fillText(demandInfo.publishTime, startx / canvasData.pixelRatio, 95 / canvasData.pixelRatio);
		ctx.closePath();
		ctx.beginPath();
		ctx.setFontSize(24 / canvasData.pixelRatio);
		ctx.setFillStyle('#1a1a1a');
		ctx.fillText('国家：' + demandInfo.countryOrigin, 49 / canvasData.pixelRatio, 147 / canvasData.pixelRatio);
		ctx.closePath();
		ctx.beginPath();
		ctx.setFontSize(24 / canvasData.pixelRatio);
		ctx.setFillStyle('#1a1a1a');
		ctx.fillText('求购量：' + (demandInfo.weight && demandInfo.weight != '' ? demandInfo.weight + '吨' : '-'), 375 / canvasData.pixelRatio, 147 / canvasData.pixelRatio);
		ctx.closePath();
		ctx.beginPath();
		ctx.setFontSize(24 / canvasData.pixelRatio);
		ctx.setFillStyle('#1a1a1a');
		ctx.fillText('厂号：' + (demandInfo.vendorNo && demandInfo.vendorNo != '' ? demandInfo.vendorNo : '-'), 49 / canvasData.pixelRatio, 191 / canvasData.pixelRatio);
		ctx.closePath();
		ctx.beginPath();
		ctx.setFontSize(24 / canvasData.pixelRatio);
		ctx.setFillStyle('#1a1a1a');
		ctx.fillText('接货地：' + (demandInfo.city && demandInfo.city != '' ? demandInfo.city : '-'), 375 / canvasData.pixelRatio, 191 / canvasData.pixelRatio);
		ctx.closePath();

		ctx.beginPath();
		ctx.setFontSize(20 / canvasData.pixelRatio);
		ctx.setFillStyle('#4c4c4c');
		ctx.fillText('采购意向价格：***RMB/KG', 49 / canvasData.pixelRatio, 262 / canvasData.pixelRatio);
		ctx.closePath();
		ctx.beginPath();
		ctx.setFontSize(20 / canvasData.pixelRatio);
		ctx.setFillStyle('#4c4c4c');
		ctx.fillText('买家联系方式：' + (demandInfo.contactMobileNo ? (demandInfo.contactMobileNo.substring(0, 3) + '********') : '-'), 49 / canvasData.pixelRatio, 302 / canvasData.pixelRatio);
		ctx.closePath();
		ctx.beginPath();
		ctx.setFontSize(20 / canvasData.pixelRatio);
		ctx.setFillStyle('#4c4c4c');
		ctx.fillText('要求：******', 49 / canvasData.pixelRatio, 342 / canvasData.pixelRatio);
		ctx.closePath();

		/*ctx.beginPath();
		ctx.setStrokeStyle('#e6e6e6');
		ctx.setFillStyle('#e6e6e6');
		ctx.moveTo(39 / canvasData.pixelRatio, 386 / canvasData.pixelRatio);
		ctx.lineTo(696 / canvasData.pixelRatio, 386 / canvasData.pixelRatio);
		ctx.closePath();
		ctx.beginPath();*/
		// 按钮
		ctx.beginPath();
		ctx.setStrokeStyle('#077131');
		ctx.setLineWidth(1);
		roundRect(ctx, 235 / canvasData.pixelRatio, 373 / canvasData.pixelRatio, 120 / canvasData.pixelRatio, 48 / canvasData.pixelRatio, 48);
		//ctx.strokeRect(100 / canvasData.pixelRatio, 397 / canvasData.pixelRatio, 220 / canvasData.pixelRatio, 48 / canvasData.pixelRatio);
		//ctx.fill();
		ctx.stroke();
		ctx.closePath();

		ctx.beginPath();
		ctx.setFontSize(20 / canvasData.pixelRatio);
		ctx.setFillStyle('#077131');
		ctx.fillText('查看', 282 / canvasData.pixelRatio, 404 / canvasData.pixelRatio);
		ctx.closePath();
		// 外面方框
		ctx.beginPath();
		ctx.setStrokeStyle('#077131');
		ctx.setFillStyle('#077131');
		roundRect(ctx, 385 / canvasData.pixelRatio, 373 / canvasData.pixelRatio, 120 / canvasData.pixelRatio, 48 / canvasData.pixelRatio, 48);
		//ctx.strokeRect(385 / canvasData.pixelRatio, 397 / canvasData.pixelRatio, 220 / canvasData.pixelRatio, 48 / canvasData.pixelRatio);
		ctx.fill();
		ctx.closePath();
		ctx.beginPath();
		ctx.setFontSize(20 / canvasData.pixelRatio);
		ctx.setFillStyle('#ffffff');
		ctx.fillText('报价', 425 / canvasData.pixelRatio, 404 / canvasData.pixelRatio);
		ctx.closePath();
		// 虚线
		ctx.beginPath();
		ctx.setStrokeStyle('#e6e6e6');
		ctx.setLineWidth(1);
		ctx.setLineDash([2, 3], 2);
		ctx.closePath();
		ctx.beginPath();
		ctx.moveTo(39 / canvasData.pixelRatio, 221 / canvasData.pixelRatio);
		ctx.lineTo(721 / canvasData.pixelRatio, 221 / canvasData.pixelRatio);
		ctx.stroke();
		ctx.closePath();
		// 虚线
		ctx.beginPath();
		ctx.setStrokeStyle('#e6e6e6');
		ctx.setLineWidth(1);
		ctx.setLineDash([2, 3], 2);
		ctx.closePath();
		ctx.beginPath();
		ctx.moveTo(39 / canvasData.pixelRatio, 362 / canvasData.pixelRatio);
		ctx.lineTo(721 / canvasData.pixelRatio, 362 / canvasData.pixelRatio);
		ctx.stroke();
		ctx.closePath();
		console.log('getSharePic------findish------------------------------1');
		/*var drawCallBack = function () {
			return new Promise(function(resolve, reject){
				uni.canvasToTempFilePath({
					x: 0,
					y: 0,
					width: canvasData.windowWidth,
					height: canvasData.windowHeight,
					destWidth: (canvasData.windowWidth) * (canvasData.pixelRatio),
					destHeight: 696 * (canvasData.pixelRatio),
					canvasId: 'myCanvas',
					quality: 1,
					success: function (resdraw) {
						console.log("要存储图片");
						uni.setStorageSync('shareCanvasPic', '');
						uni.setStorageSync('shareCanvasPic', resdraw.tempFilePath);
						resolve(resdraw);
					}
				});
			});
		};*/
		ctx.draw(true, function () {
			console.log('getSharePic------drawSuccess------------------------------');
			resolve(saveCanvas(canvasData));
		});
		console.log('getSharePic------findish------------------------------');
	});
}

// 绘制圆角矩形
function roundRect(ctx, x, y, w, h, r) {
	if (w < 2 * r) {
		r = w / 2;
	}
	if (h < 2 * r) {
		r = h / 2;
	}
	ctx.beginPath();
	ctx.moveTo(x + r, y);
	ctx.arcTo(x + w, y, x + w, y + h, r);
	ctx.arcTo(x + w, y + h, x, y + h, r);
	ctx.arcTo(x, y + h, x, y, r);
	ctx.arcTo(x, y, x + w, y, r);
	ctx.stroke();
	ctx.closePath();
	return this;
}

	function saveCanvas(canvasData) {
	return new Promise(function(resolve, reject){
		console.log('getSharePic------new Promise(canvasToTempFilePath)------------------------------');
		uni.canvasToTempFilePath({
			x: 0,
			y: 0,
			width: canvasData.windowWidth,
			height: canvasData.windowHeight,
			destWidth: (canvasData.windowWidth) * (canvasData.pixelRatio),
			destHeight: 696 * (canvasData.pixelRatio),
			canvasId: 'myCanvas',
			quality: 1,
			success: function (resdraw) {
				console.log("canvasToTempFilePath 要存储图片");
				uni.setStorageSync('shareCanvasPic', '');
				uni.setStorageSync('shareCanvasPic', resdraw.tempFilePath);
				resolve(resdraw);
			}
		});
	});
}

//预处理图片
function preHandlePic(obj){
	if(!obj.picFile[0].url){
		console.log('no-logo');
		obj.picFile[0].url='https://img.malicn.com/v1/tfs/T1fRZTBXVT1R4cSCrK.png';
	}
    for (var i = 0; i < obj.picFile.length; i++) {
		(function(i){
			if(obj.picFile[i].url!=''){
				uni.getImageInfo({
					src:obj.picFile[i].url,
					success(res) {
						obj.picFile[i].width = parseInt(res.width/obj.pixelRatio);
						obj.picFile[i].height = parseInt(res.height/obj.pixelRatio);
						obj.picFile[i].url = res.path
					}
				})
			}
		})(i);  
    }
	return obj;
}

//截取
 function   FUNsubStringFn(str, len, hasDot) {
	var newLength = 0;
	var newStr = "";
	var chineseRegex = /[^\x00-\xff]/g;
	var singleChar = "";
	var strLength = str.replace(chineseRegex, "**").length;
	for (var i = 0; i < strLength; i++) {
		singleChar = str.charAt(i).toString();
		if (singleChar.match(chineseRegex) != null) {
			newLength += 2;
		}
		else {
			newLength++;
		}
		if (newLength > len) {
			break;
		}
		newStr += singleChar;
	}

	if (hasDot && strLength > len) {
		newStr += "...";
	}

	return newStr;
}

module.exports = {
	getSharePic,
	preHandlePic
}